<template>
  <div class="zero-drift tapStyle secondary-page-mode">
    <div class="secondary-toolbar">
      <span>数据更新时间: {{ refreshTime }}</span> &emsp;
      <span class="timing-text"><b>{{ timing }}</b>S后</span>&nbsp;
      <el-button @click="refreshDate"><i class="el-icon-refresh"></i>刷新</el-button>
    </div>
    <div class="currency-mode-wrap">
      <div class="tablebox" style="height: 100%">
        <el-table
          :data="tableData"
          border
          :span-method="objectSpanMethod"
          style="width: 100%">
          <el-table-column
            type="index"
            label="序号"
            :index="indexMethod"
            width="50">
          </el-table-column>
          <el-table-column
            prop="category"
            label="类别">
          </el-table-column>
          <el-table-column
            prop="parameter"
            label="参数">
          </el-table-column>
          <el-table-column
            prop="state"
            label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.state === 0" class="abnormal"><i></i>超上限</span>
              <span v-if="scope.row.state === 1" class="normal"><i></i>正常</span>
              <span v-if="scope.row.state === 2">-</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="currentValue"
            label="当前值">
          </el-table-column>
          <el-table-column
            prop="normalRange"
            label="正常范围">
          </el-table-column>
          <el-table-column
            prop="company"
            label="单位">
          </el-table-column>
          <el-table-column
            prop="uploadTime"
            label="上传时间">
          </el-table-column>
          <el-table-column
            prop="record"
            label="修改记录">
          </el-table-column>
          <el-table-column
            prop="operation"
            label="操作">
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "",
    data() {
      return {
        timing:60,//倒计时秒数
        timingTimer:null,//倒计时定时器
        refreshTime:new Date().format('yyyy-MM-dd hh:mm:ss'),//页面数据刷新时间
        tableData:[{
          category: "化学需氧量",
          parameter: '消解温度',
          state:1,
          currentValue: 1,
          normalRange: 1,
          company:'1',
          uploadTime:'1',
          record:'1',
          operation:'1',
        },{
          category: "化学需氧量",
          parameter: '消解时长',
          state:0,
          currentValue: 1,
          normalRange: 1,
          company:'1',
          uploadTime:'1',
          record:'1',
          operation:'1',
        },{
          category: "化学需氧量",
          parameter: '量程上限',
          state:1,
          currentValue: 1,
          normalRange: 1,
          company:'1',
          uploadTime:'1',
          record:'1',
          operation:'1',
        },{
          category: "氨氮",
          parameter: '消解时长',
          state:2,
          currentValue: 1,
          normalRange: 1,
          company:'1',
          uploadTime:'1',
          record:'1',
          operation:'1',
        },{
          category: "氨氮",
          parameter: '量程上限',
          state:0,
          currentValue: 1,
          normalRange: 1,
          company:'1',
          uploadTime:'1',
          record:'1',
          operation:'1',
        }],
      };
    },
    methods:{
      //点击刷新按钮直接刷新数据
      refreshDate(){
        clearInterval(this.timingTimer);//清除倒计时定时器
        this.timing = 60;//重置刷新时间
        this.countDown();//刷新数据后开启倒计时函数
        this.refreshTime = new Date().format('yyyy-MM-dd hh:mm:ss');//更新页面数据刷新时间
      },
      //倒计时60s
      countDown(){
        this.timingTimer = setInterval(()=>{
          if(this.timing === 0){
            this.timing = 60;
          }else{
            this.timing--;
          }
        },1000);
      },
      adda(inedx,prop,key){
        let name = this.tableData[inedx][prop];
        let row = 0;
        for(let i=inedx;i<this.tableData.length;i++){
          if(name == this.tableData[i][prop]){
            row++
          }else{
            break;
          }
        }
        this.tableData[inedx][key] = row;
        return row
      },
      objectSpanMethod({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 1) {
          if(row.sf){
            return{
              colspan:1,
              rowspan:row.sf
            }
          }else{
            return{
              colspan:1,
              rowspan:0
            }
          }
        }
      }
    },
    mounted(){
      // this.createdChart();
      this.countDown();
    },
    created() {
      this.$store.commit("setShowlefttree", true);
      for(let i=0;i<this.tableData.length;i++){
        let num = this.adda(i,'category','sf');
        i+=num-1
      }
    }
  };
</script>

<style scoped lang="less">
  .zero-drift .currency-mode-wrap{
    padding: 0;
    border: none;
  }
  .timing-text{
    font-size: 16px;
    b{
      display: inline-block;
      width: 24px;
    }
  }
  .fault,.abnormal,.normal{
    i{
      display: inline-block;
      vertical-align: middle;
      margin-bottom: 2px;
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: #c64522;
      margin-right: 3px;
    }
  }
  .abnormal i{
    background: #c64522;
  }
  .normal i{
    background: #67c622;
  }
  .fault i{
    background: #dfae1c;
  }
</style>

